#ifndef CONDVAR_H_
#define CONDVAR_H_

#include "Mutex.h"

namespace utils {

class CondVar {
    pthread_cond_t  m_cond;
    Mutex&          m_lock;

public:
    CondVar(Mutex& mutex) : m_lock(mutex) { pthread_cond_init(&m_cond, NULL); }
    virtual ~CondVar() { pthread_cond_destroy(&m_cond); }

    int wait() { return  pthread_cond_wait(&m_cond, &(m_lock.m_mutex)); }
    int signal() { return pthread_cond_signal(&m_cond); }
    int broadcast() { return pthread_cond_broadcast(&m_cond); }

private:
	CondVar();
};

} /* namespace utils */

#endif /* CONDVAR_H_ */
